var t = require("../../../../@babel/runtime/helpers/toConsumableArray"), e = getApp(), a = require("../../../../utils/themeSkin/skinBehavior");

Page({
    behaviors: [ a ],
    data: {
        navInd: 0,
        searchKey: "",
        show: !1,
        showIndex: "",
        datainfo: [],
        list: [],
        display_set: {},
        userLeave: [],
        is_agent: "",
        level_id: {
            name: "",
            id: ""
        },
        orderby: {
            name: "",
            id: ""
        },
        browse: {
            name: "",
            id: ""
        },
        isLoadMore: !0,
        page: 1,
        total_page: 0
    },
    onLoad: function(t) {
        this.init(), this.getData(), this.getList(), wx.setNavigationBarTitle({
            title: "客户中心"
        });
    },
    toPlugin: function(t) {
        var e = t.currentTarget.dataset.name;
        "material-center" == e ? wx.navigateTo({
            url: "/packageA/others/materialCenter/materialCenter"
        }) : "article" == e ? wx.navigateTo({
            url: "/packageA/member/notice/notice"
        }) : "video-share" == e ? wx.navigateTo({
            url: "/packageC/video_goods/VideoList/VideoList"
        }) : "micro-communities" == e && wx.navigateTo({
            url: "/packageC/micro_communities/microIndex/microIndex"
        });
    },
    goTrack: function() {
        wx.navigateTo({
            url: "/packageF/others/customerCenter/customerCenterTrack/customerCenterTrack?is_type=" + this.data.navInd
        });
    },
    telCall: function(t) {
        var e = t.currentTarget.dataset.phone;
        wx.makePhoneCall({
            phoneNumber: e
        });
    },
    onCopyWechat: function(t) {
        var e = t.currentTarget.dataset.wechat;
        wx.setClipboardData({
            data: e,
            success: function() {
                wx.hideToast(), wx.showModal({
                    content: "复制微信号成功",
                    showCancel: !1
                });
            }
        });
    },
    onConfirm: function(t) {
        var e = t.detail.value;
        0 == this.data.showIndex ? this.setData({
            "level_id.id": e.id,
            "level_id.name": e.level_name
        }) : 1 == this.data.showIndex ? (console.log(e, "dddddddddddd"), this.setData({
            is_agent: e.id
        })) : 2 == this.data.showIndex ? this.setData({
            orderby: e
        }) : this.setData({
            browse: e
        }), this.setData({
            show: !1
        }), this.getList();
    },
    onCancel: function() {
        this.setData({
            show: !1
        });
    },
    tapNav: function(t) {
        var e = t.currentTarget.dataset.key;
        this.setData({
            navInd: e
        }), this.init(), this.getList();
    },
    init: function() {
        this.setData({
            isLoadMore: !0,
            page: 1,
            total_page: 0,
            keyword: "",
            is_agent: "",
            "level_id.name": "",
            "level_id.id": "",
            "orderby.name": "注册时间倒序",
            "orderby.id": 0,
            "browse.name": "",
            "browse.id": ""
        });
    },
    setShowInd: function(t) {
        console.log(t);
        var e = t.currentTarget.dataset.key;
        0 == e && 0 == this.data.userLeave.length && this.getUser(), this.setData({
            showIndex: e,
            show: !0
        });
    },
    onClickLeft: function() {
        this.setData({
            show: !1
        });
    },
    onClickRight: function() {
        console.log(this.data.showIndex), this.setData({
            show: !1
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多了");
    },
    getData: function() {
        var t = this, a = e.getNetAddresss("plugin.customer-center.frontend.controllers.index.index");
        e._postNetWork({
            url: a,
            success: function(e) {
                var a = e.data;
                1 == a.result ? t.setData({
                    datainfo: a.data
                }) : wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getUser: function() {
        var a = this, s = e.getNetAddresss("plugin.customer-center.frontend.controllers.index.get-level-list");
        e._postNetWork({
            url: s,
            success: function(e) {
                var s = e.data;
                if (1 == s.result) {
                    var o = s.data.level_list;
                    o = [ {
                        id: "",
                        level_name: "请选择会员等级"
                    } ].concat(t(o)), console.log(o), a.setData({
                        userLeave: o
                    }), console.log(a.data.userLeave);
                } else wx.showToast({
                    icon: "none",
                    title: s.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    onCopy: function() {
        wx.setClipboardData({
            data: this.data.datainfo.member.invite_code,
            success: function(t) {}
        });
    },
    onChange: function(t) {
        console.log(t), this.setData({
            searchKey: t.detail
        });
    },
    getList: function() {
        var t = this, a = this, s = {
            search: {
                level_type: Number(this.data.navInd),
                keyword: this.data.searchKey
            }
        };
        s.search.is_agent = this.data.is_agent, s.search.orderby = this.data.orderby.id, 
        this.data.level_id && this.data.level_id.id && (s.search.level_id = this.data.level_id.id), 
        this.data.browse && this.data.browse.id && (s.search.browse = this.data.browse.id);
        var o = e.getNetAddresss("plugin.customer-center.frontend.controllers.index.get-customer-list");
        e._postNetWork({
            url: o,
            data: s,
            success: function(e) {
                var s = e.data;
                1 == s.result ? (t.data.isLoadMore = !0, t.data.total_page = s.data.customer_list.last_page, 
                t.data.total_page || (t.data.total_page = 0), t.setData({
                    list: s.data.customer_list.data,
                    display_set: s.data.display_set
                }), wx.setNavigationBarColor({
                    frontColor: "#ffffff",
                    backgroundColor: a.data.themeBaseColor,
                    animation: {
                        duration: 400,
                        timingFunc: "easeIn"
                    }
                })) : wx.showToast({
                    icon: "none",
                    title: s.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getMoreData: function() {
        var t = this, a = "";
        if (this.data.isLoadMore = !1, !(this.data.page >= this.data.total_page)) {
            var s = {
                search: {
                    level_type: Number(this.data.navInd),
                    keyword: this.data.searchKey
                }
            };
            s.search.is_agent = this.data.is_agent, s.search.orderby = this.data.orderby.id, 
            this.data.level_id && this.data.level_id.id && (s.search.level_id = this.data.level_id.id), 
            this.data.browse && this.data.browse.id && (s.search.browse = this.data.browse.id), 
            this.data.page = this.data.page + 1, s.page = this.data.page, a = e.getNetAddresss("plugin.customer-center.frontend.controllers.index.get-customer-list"), 
            e._postNetWork({
                url: a,
                data: s,
                success: function(e) {
                    var a = e.data;
                    1 == a.result ? (t.data.isLoadMore = !0, t.setData({
                        list: t.data.list.concat(a.data.customer_list.data)
                    })) : (t.data.page = t.data.page - 1, t.isLoadMore = !1, wx.showToast({
                        icon: "none",
                        title: a.msg,
                        duration: 1500
                    }));
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    onShareAppMessage: function() {}
});